package com.xjj.datarources.config;

import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @name: xjj
 * @date: 2021/6/4 11:15
 */
@Configuration
public class MessageListenerConfig {

    @Resource
    private CachingConnectionFactory cachingConnectionFactory;

    @Resource
    private MyAckReceiver myAckReceiver;



    @Bean
    public SimpleMessageListenerContainer simpleMessageListenerContainer(){


        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cachingConnectionFactory);
        container.setConcurrentConsumers(2);
        container.setMaxConcurrentConsumers(4);
        container.setQueueNames("queue_work", "topic.work2");
        container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        container.setMessageListener(myAckReceiver);
        return container;
    }


}
